Javascript: QuickStart Guide - Effective Javascript Programming (Javascript, Programming, HTML, CSS) by William Fischer

Javascript: QuickStart Guide - Effective Javascript Programming (Javascript, Programming, HTML, CSS) by William Fischer

Author:William Fischer
Language: eng
Format: mobi
Published: 2016-02-28T22:00:00+00:00


It is important to note that, inside the body of the function, the global variable is given less precedence than a local variable of the same name. If you happen to declare a variable or a function name same as a global variable it is recommended to, effectively hide it. Take a look at this example –

<html>

<body onload = checkscope();>

<script type = "text/javascript">

<!--

var myVar = "global"; // Declare a global variable

function checkscope( ) {

var myVar = "local"; // Declare a local variable

document.write(myVar);

}

//-->

</script>

</body>

</html>

This is the OUTPUT of the following program

Local

JavaScript Variable Names

There are so many factors that you should remember before you name your variable in a JavaScript program. Here is a list of things you need to consider before creating a variable –

It is the rule of thumb that you absolutely refrain from using any of the already reserved keywords of JavaScript as your variable names. The list of keywords that are reserved is mentioned in the next section. For example, words like Boolean or break are not valid variable names.

In JavaScript, the variable names may contain a number but it cannot start with a numeral (from 0 to 9). They must either begin with a letter or an underscore. For example, a valid variable name is test123 or _123test but 123test is invalid.

Like mentioned before JavaScript is case sensitive and it is possible for the same word to be a variable with different characterization. For example, money and Money are two different words and can be used as two different variables.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.